<template>
  <!-- 风险点管理 -->
  <div class="riskpoint">
    <basic-container>
      <avue-crud 
        :option="option"
        :table-loading="loading"
        :data="data.filter((item) => assessType.includes(item.isassess))"
        :page.sync="page"
        :permission="permissionList"
        :before-open="beforeOpen"
        v-model="form"
        ref="crud"
        @row-update="rowUpdate"
        @row-save="rowSave"
        @row-del="rowDel"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
      >
        
        <!-- 左上方菜单 -->
        <template slot="menuLeft">
          <el-button 
            type="danger"
            size="small"
            icon="el-icon-delete"
            plain
            v-if="permission.riskpoint_delete"
            @click="handleDelete">
            删 除
          </el-button>

          <el-button 
            type="success" 
            size="small" 
            plain 
            icon="el-icon-upload2" 
            @click="handleImport">
            导 入
          </el-button>

          <el-button
            type="warning"
            size="small"
            plain
            icon="el-icon-download"
            @click="handleExport">
            导 出
          </el-button>

          <el-button 
            type="primary" 
            size="small" 
            plain 
            icon="el-icon-download" 
            @click="handleExportInformCard">
            导出彩色风险告知卡（A2）
          </el-button>

          <el-radio v-model="assessType" label="12">全部</el-radio>
          <el-radio v-model="assessType" label="2">待评估风险点</el-radio>

        </template>

        <!-- 主要事故表格自定义 -->
        <template slot="zysglx" slot-scope="scope">
          <div>{{formatMainFault(scope.row)}}</div>
        </template>

        <!-- 风险等级表格自定义 -->
        <template slot="fxdj" slot-scope="scope">
          <div>
            <div :class="{'fxdj_a' : fxdjObj[scope.row['fxdj']] === 'A', 'fxdj_b' : fxdjObj[scope.row['fxdj']] === 'B', 'fxdj_c' : fxdjObj[scope.row['fxdj']] === 'C', 'fxdj_d' : fxdjObj[scope.row['fxdj']] === 'D' }">
              {{fxdjObj[scope.row['fxdj']] || "-"}}
            </div>
          </div>
        </template>

        <!-- 现场照片表格自定义 -->
        <template slot="xczp" slot-scope="scope">
          <div class="ope_row_div">
            <span v-if="scope.row['xczp'] === '' || scope.row['bladeFiles'].length === 0">-</span>
            <el-button v-else type="text" @click="handleViewPhoto(scope.row)">查看</el-button>
          </div>
        </template>

        <!-- 评估状态表格自定义 -->
        <template slot="isassess" slot-scope="scope">
          <div>
            <div class="not_assess" v-if="scope.row['isassess'] === '2'">待评估</div>
            <div class="is_assess" v-if="scope.row['isassess'] === '1'">已评估</div>
          </div>
        </template>

        <!-- 风险点评估表格自定义 -->
        <template slot="fxdpg" slot-scope="scope">
          <div class="ope_row_div">
            <el-button type="text" @click="handleAssessHistory(scope.row['id'])">评估历史</el-button>
            <el-button type="text" @click="handleAssess(scope.row['id'])">评估</el-button>
          </div>
        </template>

        <!-- 风险点管控表格自定义 -->
        <template slot="fxdgk" slot-scope="scope">
          <div class="ope_row_div">
            <el-button 
              type="text" 
              @click="handleRiskControl(scope.row, updateLabel)">
              更新措施
            </el-button>
            <el-button 
              type="text" 
              @click="handleRiskControl(scope.row, viewLabel)"
              :disabled="scope.row['riskControlId'] === '' || scope.row['riskControlId'] === undefined">
              查看
            </el-button>
          </div>
        </template>

        <!-- 地图表单自定义 -->
        <template slot="mapForm">
          <div v-if="showMap">
            <baidu-map class="map" :center="center" :zoom="zoom" @ready="handler">
              <el-input placeholder="关键词查询" v-model="searchWord" style="position:absolute;top:10px;left:10px;width:180px;">
                <template slot="append">
                  <el-button icon="el-icon-search" id="citySearch"></el-button>
                </template>
              </el-input>

              <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
              <bm-marker :position="mapPosition" :dragging="dragging"></bm-marker>
            </baidu-map>
          </div>
        </template>

        <!-- 警示标志表单自定义 -->
        <template slot="jsbzForm">
          <div v-if="dialogType !== 'view'">
            <el-button 
              type="success" 
              size="small" 
              @click="handleCountryLogo">
              选择国家标识
            </el-button>

            <el-button 
              size="small" 
              type="primary"
              style="margin-left: 10px;" 
              @click="uploadJSBZ">
              上传标识
            </el-button>
            <span style="margin-left: 10px; color: #606266; font-size: 12px;">只能上传图片，最多选择3张</span>
            <input 
              accept="image/*" 
              ref="jsbzUpload" 
              id="jsbzUpload" 
              style="display: none;"
              type="file" 
              @change="jsbzUpload" 
              multiple />

          </div>
        </template>

        <!-- 警示标志内容表单自定义 -->
        <template slot="jsbzContentForm">
          <div class="jsbz_content">
            <el-tag
              v-for="(item, index) in jsbzFileList"
              :key="index"
              type="info" 
              :closable="dialogType !== 'view'" 
              @close="handleRemoveJSBZ(index)"
            >
              <img 
                :src="item.response.data.fileUrl" 
                @click="previewJSBZ(item)" 
                alt />
            </el-tag>
          </div>
        </template>

        <!-- 现场图片表单自定义 -->
        <template slot="xczpForm">
          <div v-if="dialogType !== 'view'">
            <el-button 
              size="small" 
              type="primary"
              @click="uploadXCZP">
              上传图片
            </el-button>
            <span style="margin-left: 10px; color: #606266; font-size: 12px;">只能上传图片，最多选择3张</span>
            <input 
              accept="image/*" 
              ref="xczpUpload" 
              id="xczpUpload" 
              style="display: none;" 
              type="file" 
              @change="xczpUpload" 
              multiple />
          </div>
        </template>

        <!-- 现场照片内容表单自定义 -->
        <template slot="xczpContentForm">
          <div class="xczp_content">
            <el-tag
              v-for="(item, index) in xczpFileList"
              :key="index"
              type="info" 
              :closable="dialogType !== 'view'" 
              @close="handleRemoveXCZP(index)"
            >
              <img 
                :src="item.response.data.fileUrl" 
                @click="previewXCZP(item)" 
                alt />
            </el-tag>
          </div>
        </template>

      </avue-crud>

      <!-- 弹窗：导入 -->
      <importriskmanagement 
        :excelBox="excelBox" 
        @uploadAfter="uploadAfter" 
        @handleCloseExcelBox="handleCloseExcelBox">
      </importriskmanagement>

      <!-- 弹窗：图片 -->
      <viewpicture 
        :localPicBox="localPicBox" 
        :localPictures="localPictures" 
        :viewPicTitle="viewPicTitle" 
        @confirmViewPicture="confirmViewPicture" 
        @handleClosePicBox="handleClosePicBox">
      </viewpicture>

      <!-- 弹窗：评估历史 -->
      <assesshistory 
        :assessHistoryDialog="assessHistoryDialog" 
        :selectRiskId="selectRiskId"
        @confirmAssessHistory="confirmAssessHistory" 
        @handleCloseAssessHistory="handleCloseAssessHistory">
      </assesshistory>

      <!-- 弹窗：风险评估 -->
      <riskassess 
        :riskAssessDialog="riskAssessDialog" 
        :selectRiskId="selectRiskId"
        @cancelSaveRiskAssess="cancelSaveRiskAssess" 
        @saveRiskAssessSuccess="saveRiskAssessSuccess" 
        @handleCloseRiskAssess="handleCloseRiskAssess">
      </riskassess>

      <!-- 弹窗：风险点管控 -->
      <riskcontrol 
        :riskControlDialog="riskControlDialog" 
        :selectRiskId="selectRiskId" 
        :selectRiskControlId="selectRiskControlId" 
        :controlType="controlType" 
        :selectedRisk="selectedRisk"
        @saveRiskControl="saveRiskControl" 
        @cancelSaveRiskControl="cancelSaveRiskControl" 
        @confirmSaveRiskControl="confirmSaveRiskControl" 
        @handleCloseRiskControl="handleCloseRiskControl">
      </riskcontrol>

      <!-- 弹窗：选择国家标识 -->
      <countrylogo 
        :countryLogoDialog="countryLogoDialog" 
        :uploadList="uploadList" 
        @chooseCountryLogo="chooseCountryLogo" 
        @cancelChooesCountryLogo="cancelChooesCountryLogo" 
        @handleCloseCountryLogo="handleCloseCountryLogo">
      </countrylogo>
      
    </basic-container>
  </div>
</template>

<script>
import { getList, add, update, remove, getDeptList, getMainFaultList, uploadFiles } from "@/api/saferisk/riskpoint";
import { mapGetters } from "vuex";
import { getToken } from "@/util/auth";
import { riskpointColumn } from './constant/riskpoint.js';
import assesshistory from "./components/assesshistory.vue";
import importriskmanagement from './components/importriskmanagement.vue';
import viewpicture from './components/viewpicture.vue';
import riskassess from './components/riskassess.vue';
import riskcontrol from './components/riskcontrol.vue';
import countrylogo from './components/countrylogo.vue';

export default {
  components: { 
    assesshistory,
    importriskmanagement,
    viewpicture,
    riskassess,
    riskcontrol,
    countrylogo
  }, 
  data() {
    return {
      // 风险点辨识列表
      assessType: "12",
      selectionList: [],
      data: [],
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: this.$pageSize,
        currentPage: 1,
        total: 0
      },
      option: {
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchSpan: 5,
        searchMenuSpan: 4,
        refreshBtn: true,
        columnBtn: false,
        border: true,
        viewBtn: true,
        selection: true,
        dialogClickModal: false,
        menuWidth: 200,
        menuTitle: "风险点信息",
        editBtnText: "修改",
        addTitle: "新增风险点辨识",
        viewTitle: "查看风险点辨识",
        column: riskpointColumn
      },
      // 警示标志
      jsbzFileList: [],
      // 现场照片
      xczpFileList: [],
      // 地图
      mapPosition: {
        lng: 121.4472540000,
        lat: 31.3236200000
      },
      center: {
        lng: 121.4472540000,
        lat: 31.3236200000
      },
      zoom: 10,
      dragging: false,
      showMap: true,
      searchWord: "",
      dialogType: "",
      // 主要事故列表
      mainFaults: {},
      // 弹窗：导入
      excelBox: false,
      // 弹窗：查看图片
      localPicBox: false,
      localPictures: [],
      viewPicTitle: "",
      // 弹窗：风险评估
      riskAssessDialog: false,
      selectRiskId: "",
      // 弹窗：评估历史
      assessHistoryDialog: false,
      // 弹窗：风险点管控
      riskControlDialog: false,
      selectRiskControlId: "",
      selectedRisk: {},
      updateLabel: "UPDATE",
      viewLabel: "VIEW",
      controlType: "",
      // 弹窗：选择国家标识
      countryLogoDialog: false,
      uploadList: [],
      fxdjObj: {
        "1": "A",
        "2": "B",
        "3": "C",
        "4": "D"
      }
    };
  },
  computed: {
    ...mapGetters(["permission"]),

    // 风险点辨识列表按钮权限
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.riskpoint_add, false),
        viewBtn: this.vaildData(this.permission.riskpoint_view, false),
        delBtn: this.vaildData(this.permission.riskpoint_delete, false),
        editBtn: this.vaildData(this.permission.riskpoint_edit, false)
      };
    },

    // 风险点辨识勾选项ID
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }

  },
  watch: {

    // 表单经度
    'form.jd' (val) {
      if(val) {
        this.mapPosition.lng = val / 1
      }
    },
    
    // 表单纬度
    'form.wd' (val) {
      if(val) {
        this.mapPosition.lat = val / 1
      }
    }
    
  },
  mounted() {
    this.initData();
  },
  methods: {

    // 初始化数据
    initData() {
      var tenantId = JSON.parse( localStorage.getItem("saber-tenantId") ).content;
      getDeptList(tenantId).then(res => {
        const column = this.findObject(this.option.column, "ssbm");
        column.dicData = res.data.data;
      }).then(() => {
        this.getMainFaults();
      });
    },

    // 获取主要事故列表
    getMainFaults() {
      getMainFaultList().then(res => {
        this.mainFaults = {};
        res.data.data.forEach(item => {
          this.mainFaults[item.dictKey] = item.dictValue;
        });
      }).then(() => {
        this.onLoad(this.page);
      });
    },

    // 地图处理事件
    handler({BMap, map}) {
      let _this = this;
      map.addEventListener('click', function(e) {
        _this.form.jd = e.point.lng
        _this.form.wd = e.point.lat
      });
      
      _this.$nextTick(() => {
        document.getElementById('citySearch').addEventListener('click', function() {
          let localSearch = new BMap.LocalSearch(map)
          localSearch.setSearchCompleteCallback(searchResult => {
            let poi = searchResult.getPoi(0)
            if(!poi) {
              return _this.$message.warning('该地址不存在')
            } else {
              _this.center = {
                lng: poi.point.lng,
                lat: poi.point.lat
              }
              _this.form.jd = poi.point.lng
              _this.form.wd = poi.point.lat
            }
          });
          localSearch.search(_this.searchWord);
        });
      })
    },

    /**
     * 上传警示标志
    */

    // 点击上传标识按钮
    uploadJSBZ() {
      document.getElementById("jsbzUpload").click();
    },

    // 上传警示标志
    jsbzUpload(element) {
      console.log(element);
      if(this.$refs.jsbzUpload.files.length + this.jsbzFileList.length > 3) {
        this.$message.warning("最多选择3张警示标识!");
        this.$refs.jsbzUpload.value = null;
        return;
      }
      let formData = {};
      let files = this.$refs.jsbzUpload.files;
      formData = new FormData();
      for(let i = 0 ; i < files.length ; i++) {
        formData.append("files", files[i]);
      } 
      uploadFiles(formData).then(res => {
        if(!res.data.success) {
          return;
        }
        var resData = res.data.data;
        resData.forEach(item => {
          this.jsbzFileList.push({
            name: item.fileName,
            response: {
              code: 200,
              msg: "操作成功",
              success: true,
              data: item
            }
          });
        });
        this.$refs.jsbzUpload.value = null;
      });
    },

    // 删除警示标志
    handleRemoveJSBZ(index) {
      this.jsbzFileList.splice(index, 1);
    },

    /**
     * 上传现场照片
    */

    // 点击上传图片按钮
    uploadXCZP() {
      document.getElementById("xczpUpload").click();
    },

    // 上传现场照片
    xczpUpload(element) {
      console.log(element);
      if(this.$refs.xczpUpload.files.length + this.xczpFileList.length > 3) {
        this.$message.warning("最多上传3张现场图片!");
        this.$refs.xczpUpload.value = null;
        return;
      }
      let formData = {};
      let files = this.$refs.xczpUpload.files;
      formData = new FormData();
      for(let i = 0 ; i < files.length ; i++) {
        formData.append("files", files[i]);
      } 
      uploadFiles(formData).then(res => {
        if(!res.data.success) {
          return;
        }
        var resData = res.data.data;
        resData.forEach(item => {
          this.xczpFileList.push({
            name: item.fileName,
            response: {
              code: 200,
              msg: "操作成功",
              success: true,
              data: item
            }
          });
        });
        this.$refs.xczpUpload.value = null;
      });
    },

    // 删除现场照片
    handleRemoveXCZP(index) {
      this.xczpFileList.splice(index, 1);
    },
    
    // 显示主要事故列
    formatMainFault(row) {
      if(row.zysglx === undefined || typeof row.zysglx === "object") {
        return "";
      }
      var arr = row.zysglx.split(",");
      var faults = [];
      for(let i = 0 ; i < arr.length ; i++) {
        var fault = this.mainFaults[arr[i]] === undefined ? arr[i] : this.mainFaults[arr[i]];
        faults.push(fault);
      }
      return faults.join(",");
    },

    // 导出
    handleExport() {
      this.$confirm("是否导出风险点辨识列表?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let fxdmc = this.query.fxdmc !== undefined && this.query.fxdmc !== "" && this.query.fxdmc !== null ? this.query.fxdmc : "";
        let fxfl = this.query.fxfl !== undefined && this.query.fxfl !== "" && this.query.fxfl !== null ? this.query.fxfl : "";
        let ssbm = this.query.ssbm !== undefined && this.query.ssbm !== "" && this.query.ssbm !== null ? this.query.ssbm : "";
        let fxdj = this.query.fxdj !== undefined && this.query.fxdj !== "" && this.query.fxdj !== null ? this.query.fxdj : "";
        window.open(
          `/api/riskPoint/riskmanagement/export?${this.website.tokenHeader}=${getToken()}&fxdmc=${fxdmc}&fxfl=${fxfl}&ssbm=${ssbm}&fxdj=${fxdj}`
        );
      });
    },

    // 导出彩色风险告知卡（A2）
    handleExportInformCard() {
      if (this.selectionList.length === 0 || this.selectionList.length > 1) {
        this.$message.warning("请选择一条数据");
        return;
      }
      this.$confirm("是否导出彩色风险告知卡（A2）?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let selectId = this.selectionList[0].id;
        window.open(
          `/api/riskPoint/riskmanagement/exportColorRiskNotificationCard?${this.website.tokenHeader}=${getToken()}&id=${selectId}`
        );
      });
    },

    // 新增
    rowSave(row, done) {
      for(let key in row) {
        if(key.indexOf("$") >= 0) {
          delete row[key];
        }
      }
      row.fxyslb = typeof row.fxyslb === "object" ? row.fxyslb.join(",") : row.fxyslb;
      row.zysglx = typeof row.zysglx === "object" ? row.zysglx.join(",") : row.zysglx;
      row.xczp = this.xczpFileList.length === 0 ? "" : this.formatPictureIds(this.xczpFileList);
      row.jsbz = this.jsbzFileList.length === 0 ? "" : this.formatPictureIds(this.jsbzFileList);
      add(row).then(() => {
        this.onLoad(this.page);
        this.$message.success("操作成功!");
        done();
      });
    },

    // 获取现场照片ids
    formatPictureIds(filelist) {
      var ids = [];
      filelist.forEach(item => {
        ids.push(item.response.data.id);
      });
      return ids.join(",");
    },

    // 修改
    rowUpdate(row, index, done) {
      for(let key in row) {
        if(key.indexOf("$") >= 0) {
          delete row[key];
        }
      }
      row.fxyslb = typeof row.fxyslb === "object" ? row.fxyslb.join(",") : row.fxyslb;
      row.zysglx = typeof row.zysglx === "object" ? row.zysglx.join(",") : row.zysglx;
      row.xczp = this.xczpFileList.length === 0 ? "" : this.formatPictureIds(this.xczpFileList);
      row.jsbz = this.jsbzFileList.length === 0 ? "" : this.formatPictureIds(this.jsbzFileList);
      update(row).then(() => {
        this.onLoad(this.page);
        this.$message.success("操作成功!");
        done();
      });
    },

    // 删除一条
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        return remove(row.id);
      }).then(() => {
        this.onLoad(this.page);
        this.$message.success("操作成功!");
      });
    },

    // 删除多条
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        return remove(this.ids);
      }).then(() => {
        this.onLoad(this.page);
        this.$message.success("操作成功!");
        this.$refs.crud.toggleSelection();
      });
    },

    // 新增、查看、编辑弹窗打开前
    beforeOpen(done, type) {
      if(type === "add") {
        this.showMap = true;
        this.mapPosition = {
          lng: 121.4472540000,
          lat: 31.3236200000
        };
        this.center = {
          lng: 121.4472540000,
          lat: 31.3236200000
        };
        this.xczpFileList = [];
        this.jsbzFileList = [];
      } else {
        this.xczpFileList = [];
        this.form.bladeFiles.forEach(item => {
          this.xczpFileList.push({
            name: item.fileName,
            response: {
              code: 200,
              data: item,
              msg: "操作成功",
              success: true
            }
          });
        });
        this.jsbzFileList = [];
        this.form.identifyFiles.forEach(item => {
          this.jsbzFileList.push({
            name: item.fileName,
            response: {
              code: 200,
              data: item,
              msg: "操作成功",
              success: true
            }
          });
        });

        if(type === "edit") {
          this.showMap = true;
          this.center = {
            lng: this.form.jd,
            lat: this.form.wd
          };
          this.zoom = 10;
        } else if(type === "view") {
          this.showMap = false;
        }
      }
      this.dialogType = type;
      done();
    },

    // 清空搜索条件
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },

    // 搜索条件改变事件
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },

    // 勾选
    selectionChange(list) {
      this.selectionList = list;
    },

    // 清空勾选
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },

    // 换页数
    currentChange(currentPage){
      this.page.currentPage = currentPage;
      this.onLoad(this.page);
    },

    // 换每页显示数量
    sizeChange(pageSize){
      this.page.pageSize = pageSize;
      this.onLoad(this.page);
    },

    // 刷新
    refreshChange() {
      this.onLoad(this.page, this.query);
    },

    // 获取表格数据
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },

    /**
     * 弹窗：导入
    */

    // 弹出导入弹窗
    handleImport() {
      this.excelBox = true;
    },

    // 导入成功后
    uploadAfter() {
      this.excelBox = false;
      this.$message.success("上传成功");
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },

    // 关闭导入弹窗
    handleCloseExcelBox() {
      this.excelBox = false;
    },

    /**
     * 弹窗：图片
    */

    // 查看现场照片
    handleViewPhoto(row) {
      this.localPictures = row.bladeFiles;
      this.localPicBox = true;
      this.viewPicTitle = "现场照片";
    },

    // 点击图片列表中已上传的现场图片
    previewXCZP(file) {
      if(file.response && file.response.code === 200 && file.response.data && file.response.data.fileUrl) {
        this.localPictures = [file.response.data];
        this.localPicBox = true;
        this.viewPicTitle = "现场照片";
      }
    },

    // 点击图片列表中已上传的警示图片
    previewJSBZ(file) {
      if(file.response && file.response.code === 200 && file.response.data && file.response.data.fileUrl) {
        this.localPictures = [file.response.data];
        this.localPicBox = true;
        this.viewPicTitle = "警示标识";
      }
    },

    // 确认照片
    confirmViewPicture() {
      this.localPictures = [];
      this.localPicBox = false;
      this.viewPicTitle = "";
    },

    // 关闭弹窗
    handleClosePicBox() {
      this.confirmViewPicture();
    },

    /**
     * 弹窗：评估历史
    */

    // 打开评估历史弹窗
    handleAssessHistory(id) {
      this.assessHistoryDialog = true;
      this.selectRiskId = id;
    },

    // 确认风险评估历史
    confirmAssessHistory() {
      this.assessHistoryDialog = false;
      this.selectRiskId = "";
    },

    // 关闭评估历史弹窗
    handleCloseAssessHistory() {
      this.confirmAssessHistory();
    },

    /**
     * 弹窗：风险评估
    */

    // 打开风险评估弹窗
    handleAssess(id) {
      this.riskAssessDialog = true;
      this.selectRiskId = id;
    },

    // 保存风险评估成功
    saveRiskAssessSuccess() {
      this.riskAssessDialog = false;
      this.selectRiskId = "";
      this.$message.success("评估成功!");
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },

    // 取消保存风险评估
    cancelSaveRiskAssess() {
      this.riskAssessDialog = false;
      this.selectRiskId = "";
    },

    // 关闭弹窗
    handleCloseRiskAssess() {
      this.cancelSaveRiskAssess();
    },

    /**
     * 弹窗：风险点管控
    */

    // 打开风险点管控弹窗
    handleRiskControl(risk, type) {
      this.riskControlDialog = true;
      this.selectRiskId = risk.id;
      this.selectRiskControlId = risk.riskControlId;
      this.controlType = type;
      this.selectedRisk= risk;
    },

    // 保存风险管控
    saveRiskControl() {
      this.confirmSaveRiskControl();
      this.$message.success("保存风险管控成功！");
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },

    // 取消保存风险管控
    cancelSaveRiskControl() {
      this.confirmSaveRiskControl();
    },

    // 确认风险管控
    confirmSaveRiskControl() {
      this.riskControlDialog = false;
      this.selectRiskId = "";
      this.selectRiskControlId = "";
      this.controlType = this.updateLabel;
      this.selectedRisk = {};
    },

    // 关闭风险点管控弹窗
    handleCloseRiskControl() {
      this.confirmSaveRiskControl();
    },

    /**
     * 弹窗：选择国家标识
    */

    // 打开选择国家标识弹窗
    handleCountryLogo() {
      this.countryLogoDialog = true;
      this.uploadList = this.jsbzFileList;
    },

    // 选择国家标识
    chooseCountryLogo(selectLogos) {
      selectLogos.forEach(item => {
        let file = {
          name: item.bladeFile.fileName,
          response: {
            code: 200,
            msg: "操作成功",
            success: true,
            data: item.bladeFile
          }
        };
        this.jsbzFileList.push(file);
      });
      this.cancelChooesCountryLogo();
    },

    // 取消选择国家标识
    cancelChooesCountryLogo() {
      this.countryLogoDialog = false;
      this.uploadList = [];
    },

    // 关闭选择国家标识弹窗
    handleCloseCountryLogo() {
      this.cancelChooesCountryLogo();
    }

  }
};
</script>

<style lang="scss">
  @import "./styles/riskpointglobal.scss";
</style>

<style lang="scss" scpoed >
  @import "./styles/riskpointscoped.scss";
</style>